package com.lawyers.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.lawyers.common.DemandaVO;
import com.lawyers.common.UserVO;
import com.lawyers.database.DBAcciones;
import com.lawyers.form.MisDemandasForm;

public class ListarMisDemandasAction extends Action {

	private static Logger logger = Logger.getLogger(ListarMisDemandasAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		MisDemandasForm misDemandasForm = (MisDemandasForm) form;
		String accion = misDemandasForm.getAccion();
		UserVO user = (UserVO) request.getSession().getAttribute("USUARIO");

		if (user == null)
			return mapping.findForward("login");
		if ("cargar".equalsIgnoreCase(accion)) {
			response.sendRedirect("MisDemandas.do?accion=display&idDemanda="+misDemandasForm.getIdDemanda());
			return null;
		}else{
			List<DemandaVO> demandas = DBAcciones.getMisDemandas(user.getIdUsuario());
			misDemandasForm.setDemandas(demandas);
			return mapping.findForward("display");
		}
	}

}
